package ModelLayer;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Calendar;

public class Dates
{
    Date date=null;
    SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy");
    private static Dates instance;
    private String resultValid;
    
    private Dates()
    {
        
    }
    
    public static Dates getInstance()
    {
        if (instance == null)
        {
            instance= new Dates();
        }
        return instance;
    }
    
    public void isValid(String dateValid)
    {
        if(dateValid == null)
        {
             resultValid="Date not valid.";
        }
        
        sdf.setLenient(false);
        
        try
        {
            date = sdf.parse(dateValid);
            sdf.format(date);
            resultValid="Date valid.";
        }
        catch (ParseException e) 
        {
			resultValid="Date not valid.";
		} 
    }
    
    public String resultValid()
    {
        return resultValid;
    }
    
    public String newDate(int period)
    {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        c.add(Calendar.DATE, period);
        return sdf.format(c.getTime());
    }
    
    public String today()
    {
        Calendar c = Calendar.getInstance();
        c.setTime(new Date());
        return sdf.format(c.getTime());
    }
}